home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / fstwait.com / WAIT.DOC < prev    next >
Encoding:
Text File  |  1991-04-08  |  6.0 KB  |  155 lines

  1. FastWait               Copyright (c) 1991  Southern Software
  2.  
  3. Version 1.00 - 4/8/91
  4.  
  5. Allows PC's faster than 20 mhz (386/486) to properly use a delay
  6. function based upon a null looping procedure such as is used in the
  7. Turbo Pascal "Delay" procedure.  Wait is accurate for PC's as fast as
  8. 1,100 mhz equivalent!
  9.  
  10. USAGE: Simply place "FastWait" in the Uses section of your program
  11.        and replace each occurrence of "delay" in your program with
  12.        "wait".
  13.  
  14. Example-
  15. =======
  16.  
  17.      Existing program:
  18.      ----------------
  19.      Uses CRT;
  20.  
  21.      begin
  22.      writeln('This program delays for 5 seconds.);
  23.      delay(5000);
  24.      end.
  25.  
  26.      New program:
  27.      -----------
  28.      Uses FastWait, CRT;                {Now also uses "FastWait"}
  29.  
  30.      begin
  31.      writeln('This program delays for 5 seconds.);
  32.      wait(5000);                        {changed "delay" to "wait"}
  33.      end.
  34.  
  35.  
  36. User accessible variables in FastWait unit:
  37. ------------------------------------------
  38.  
  39. WaitOneMS : Number of loops required for one millisecond delay
  40. LoopsPerTick : LongInt which is # loops in timer for one
  41.                BIOS tick (18.2 ticks per second)
  42. BIOSTick : An absolute LongInt variable into the PC BIOS area
  43.                which is the system counter and is incremented 18.2
  44.                times per second.
  45.  
  46.  
  47.  
  48. Procedure in FastWait unit:
  49. --------------------------
  50.  
  51. procedure Wait( ms : word );
  52.  
  53. procedure ShortDelay(NumLoops : word);
  54. {
  55.   This procedure is for very short timing loops ( < 1ms) that cannot be
  56.   handled by the delay routine.
  57.  
  58.   The variable "LoopsPerTick" has the number of loops to do for one BIOS
  59.   tick (18.2 of these/sec). If you want to delay for "X" µs, the number
  60.   of loops required would be  "(LoopsPerTick*X) div 54945"
  61.  
  62.   This will not compile if you are using TP 4.0, 5.0 or 5.5 due to the
  63.   conditional defines.  This is because it makes use of the "asm"
  64.   statement which is not available in TP versions prior to 6.0.
  65. }
  66.  
  67.  
  68.  
  69. Technical Discussion
  70. --------------------
  71. In the Turbo CRT unit, there has been a word variable named "DelayCnt"
  72. (local variable to the CRT unit) which is the number of loops that
  73. were done in one clock tick divided by 55.  This is a decent approx-
  74. imation of the number of loops required for one millisecond (the
  75. "Delay" procedure merely called a null loop "DelayCnt" times for each
  76. millisecond specified in the call to the procedure. (Note- For those
  77. using Object Professional or Turbo Professional, this variable is called
  78. "OneMS", but the logic is identical).
  79.  
  80. Unfortunately, if the clock speed gets to about 25 mhz, the PC is so
  81. fast that the PC can do more than 65,535 loops and the null loop timer
  82. does not work.  The value 65,535 is divided by 55 to give 1,191
  83. regardless of the speed of the PC.  Subsequent calls to the delay
  84. procedure cause shorter-than-expected delays since the delay count
  85. calculated for one millisecond is too low.  This problem gets worse the
  86. faster the PC becomes.
  87.  
  88. The "Wait" procedure is a simple solution to this problem.  The number
  89. of loops done in one clock tick is stored in a LongInt rather than a
  90. word variable so the limit of 65,535 loops in one clock tick is not a
  91. problem.
  92.  
  93. Special goody if you are using TP 6.0+ (or if you want to make the
  94. assembly code below in a separate ASM file) -- A routine called
  95. "ShortDelay" is provided which will be included in the FastWait unit
  96. automatically if you are using TP 6.0+ that allows you to specify
  97. delays which are shorter than 1 millisecond (the lower limit of
  98. the "delay" and "wait" routines.
  99.  
  100.  
  101. Public Usage
  102. ------------
  103. This utility is provided for the public domain on an as-is basis
  104. free of charge.  It may be used in any programs with no royalties.
  105. Southern Software retains all rights to the code and is not liable
  106. for anything which may happen as a result of using the code.
  107.  
  108.  
  109.          ----------------end-of-author's-documentation---------------
  110.  
  111.                          Software Library Information:
  112.  
  113.                     This disk copy provided as a service of
  114.  
  115.                            Public (software) Library
  116.  
  117.          We are not the authors of this program, nor are we associated
  118.          with the author in any way other than as a distributor of the
  119.          program in accordance with the author's terms of distribution.
  120.  
  121.          Please direct shareware payments and specific questions about
  122.          this program to the author of the program, whose name appears
  123.          elsewhere in  this documentation. If you have trouble getting
  124.          in touch with the author,  we will do whatever we can to help
  125.          you with your questions. All programs have been tested and do
  126.          run.  To report problems,  please use the form that is in the
  127.          file PROBLEM.DOC on many of our disks or in other written for-
  128.          mat with screen printouts, if possible.  PsL cannot debug pro-
  129.          programs over the telephone, though we can answer questions.
  130.  
  131.          Disks in the PsL are updated  monthly,  so if you did not get
  132.          this disk directly from the PsL, you should be aware that the
  133.          files in this set may no longer be the current versions. Also,
  134.          if you got this disk from another vendor and are having prob-
  135.          lems,  be aware that  some files may have become corrupted or
  136.          lost by that vendor. Get a current, working disk from PsL.
  137.  
  138.          For a copy of the latest monthly software library newsletter
  139.          and a list of the 3,000+ disks in the library, call or write
  140.  
  141.                            Public (software) Library
  142.                                P.O.Box 35705 - F
  143.                             Houston, TX 77235-5705
  144.  
  145.                                 1-800-2424-PSL
  146.                              MC/Visa/AmEx/Discover
  147.  
  148.                           Outside of U.S. or in Texas
  149.                           or for general information,
  150.                               Call 1-713-524-6394
  151.  
  152.                           PsL also has an outstanding
  153.                           catalog for the Macintosh.
  154.  
  155.